package net.zjitc.securityloginapijwt.controller;

import net.zjitc.securityloginapijwt.utils.LoginInfoUtil;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;

/**
 * @author 罗翼侨
 * @date 2025/3/4 9:49
 */
@Controller
public class UserController {
    @RequestMapping(value = "/")
    public @ResponseBody String index(){
        return "Welcome to Spring Security";
    }
    @RequestMapping(value = "/welcome")
    public @ResponseBody String welcome(){
        return "Welcome";
    }
    @RequestMapping(value = "/toLogin")
    public String toLogin(){
        return "login";
    }
    @RequestMapping(value = "/welcome1")
    public @ResponseBody Object welcome1(Principal principal) {
        return principal;
    }
    @RequestMapping(value = "/welcome2")
    public @ResponseBody Object welcome2() {
        return SecurityContextHolder.getContext().getAuthentication();
    }
    @RequestMapping(value = "/welcome3")
    public @ResponseBody Object welcome3() {
        return LoginInfoUtil.getCurrentLoginInfo();
    }
}
